package com.sxhuayuan.parking.job;

import com.sxhuayuan.parking.task.MonthlyProfitTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDate;

/**
 * 代理分润月结算
 * 
 * @author 何龙
 * @create 2019-05-22 17:13
 */
@Component
@Lazy(false)
public class MonthlyProfitJob {
	Logger log = LoggerFactory.getLogger(getClass());

	@Resource(name = "taskExecutor")
	TaskExecutor taskExecutor;

	/**
	 * 每月一号凌晨2点 统计前一个月代理分润
	 */
	@Scheduled(cron = "0 0 2 1 1/1 ?")
	public void agentProfitStatisticsJob() {
		log.debug("分润统计月结算任务");
		try {
			LocalDate date = LocalDate.now().minusMonths(1);
			taskExecutor.execute(new MonthlyProfitTask(date));
		} catch (Exception e) {
			log.error("", e);
		}
	}
}
